package com.mmsj.maker.generator;

import com.mmsj.maker.model.DataModel;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 核心生成器
 */
public class MainGenerator {

    /**
     * 生成
     *
     * @param model 数据模型
     * @throws TemplateException
     * @throws IOException
     */
    public static void doGenerate(Object model) throws TemplateException, IOException {

      String inputRootPath = "E:\\Git_Code\\guantou-generator\\guantou-generator-demo-projects\\acm-template";
      String outputRootPath = "E:\\Git_Code\\guantou-generator";

      String inputPath;
      String outputPath;

      inputPath = new File(inputRootPath, "src/com/mmsj/acm/MainTemplate.java.ftl").getAbsolutePath();
      outputPath = new File(outputRootPath, "src/com/mmsj/acm/MainTemplate.java").getAbsolutePath();
      DynamicFileGenerator.doGenerate(inputPath, outputPath, model);

      inputPath = new File(inputRootPath, ".gitignore").getAbsolutePath();
      outputPath = new File(outputRootPath, ".gitignore").getAbsolutePath();
      StaticFileGenerator.copyFilesByHutool(inputPath, outputPath);

      inputPath = new File(inputRootPath, "README.md").getAbsolutePath();
      outputPath = new File(outputRootPath, "README.md").getAbsolutePath();
      StaticFileGenerator.copyFilesByHutool(inputPath, outputPath);

    }

    public static void main(String[] args) throws TemplateException, IOException {
        DataModel dataModel = new DataModel();
        dataModel.setAuthor("ChuXuan");
        dataModel.setLoop(false);
        dataModel.setOutputText("求和结果：");
        doGenerate(dataModel);
    }
}

